<?php

namespace App\Admin\Actions;

use App\Models\DepartmentCategory;
use Dcat\Admin\Tree\RowAction;

class DepartmentShowAction extends RowAction
{
    public function handle()
    {
        $key = $this->getKey();
        $department = DepartmentCategory::find($key);
        $department->update(['is_show' => $department->is_show ? 0 : 1]);

        return $this
            ->response()
            ->success(trans('admin.update_succeeded'))
            ->refresh();
    }

    public function title()
    {
        $icon = $this->getRow()->is_show ? 'icon-eye-off' : 'icon-eye';

        return "&nbsp;<i class='feather $icon'></i>&nbsp;";
    }
}
